package com.kebaijia.url;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author luoy
 * @date 2018/7/23 0023 下午 10:00
 * @Description: ${todo}
 */
class URLTest {

        public static void main(String[] args) throws Exception {
            //创建 URL 对象
            URL url = new URL("http://www.sina.com.cn");
            //调用 URL 对象的 openConnection 方法，获得 URLConnection
            URLConnection conn = url.openConnection();
            //调用 URLConnection 方法的 getInputStream
            InputStream in = conn.getInputStream();
            //I/O 操作
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(in));

            String line = null;
            while( (line=br.readLine()) != null ){
                System.out.println(line);
            }
            //关闭 I/O 流
            br.close();
    }

}
